home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3006 / 3006.xpi / chrome / dwhelper.jar / content / preferences-new.js < prev    next >
Text File  |  2010-01-15  |  10KB  |  271 lines

  1. /******************************************************************************
  2.  *            Copyright (c) 2006-2009 Michel Gutierrez. All Rights Reserved.
  3.  ******************************************************************************/
  4.  
  5. var pref=Components.classes["@mozilla.org/preferences-service;1"]
  6.     .getService(Components.interfaces.nsIPrefService).getBranch("dwhelper.");
  7. var Util=Components.classes["@downloadhelper.net/util-service;1"]
  8.     .getService(Components.interfaces.dhIUtilService);
  9.  
  10. function onLoad() {
  11.  
  12.     updateBCMedialink();
  13.     updateBCSmartName();
  14.     updateBCHistory();
  15.     updateBCConversion();
  16.     updateBCPlatform();
  17.     updateBCMP3Tunes();
  18.     updateBCYTInPage();
  19.     updateBCTwitter();
  20.     updateBCMaxDownloads();
  21.  
  22.     window.sizeToContent();
  23.  
  24.     var mp3tunesVisible=false;
  25.     try {
  26.         mp3tunesVisible=pref.getBoolPref("mp3tunes.visible");
  27.     } catch(e) {}
  28.     document.getElementById("tab-mp3tunes").setAttribute("collapsed",""+!mp3tunesVisible);
  29.     
  30.     if(window.arguments && window.arguments[0]) {
  31.         if(window.arguments[0].selectedPanel) {
  32.             var panel=document.getElementById(window.arguments[0].selectedPanel);
  33.             if(panel)
  34.                 document.getElementById("dwhelper-preferences-new").showPane(panel);
  35.         }
  36.         if(window.arguments[0].selectedTab) {
  37.             var tab=document.getElementById(window.arguments[0].selectedTab);
  38.             if(tab)
  39.                 tab.parentNode.parentNode.selectedTab=tab;
  40.         }
  41.     }
  42.     
  43.     if(Util.priorTo19()) {
  44.         document.getElementById("tab-mp3tunes").collapsed=true;
  45.         document.getElementById("tab-twitter").collapsed=true;
  46.     }
  47. }
  48.  
  49. function setConversionUse() {
  50.     if(document.getElementById("cb-conversion-enabled").checked)
  51.         pref.setBoolPref("conversion-was-enabled",true);
  52. }
  53.  
  54. function changeStorageDir() {
  55.     var element=document.getElementById("dwhelper-storagedir");
  56.     var nsIFilePicker = Components.interfaces.nsIFilePicker;
  57.     var fp = Components.classes["@mozilla.org/filepicker;1"]
  58.             .createInstance(nsIFilePicker);
  59.     fp.init(window, Util.getText("prompt.select-storage-dir"), nsIFilePicker.modeGetFolder);
  60.     var res=null;
  61.     res = fp.show();
  62.     if (res == nsIFilePicker.returnOK){
  63.         pref.setCharPref("storagedirectory",fp.file.path);
  64.     }
  65. }
  66.  
  67. function updateBCPlatform() {
  68.     var bcWindows=document.getElementById("bc-platform-windows");
  69.     var bcNotWindows=document.getElementById("bc-platform-notwindows");
  70.     try {
  71.         Components.classes["@mozilla.org/windows-registry-key;1"]
  72.             .createInstance(Components.interfaces.nsIWindowsRegKey);
  73.         bcWindows.setAttribute("collapsed","false");
  74.         bcNotWindows.setAttribute("collapsed","true");
  75.     } catch(e) {
  76.         bcWindows.setAttribute("collapsed","true");
  77.         bcNotWindows.setAttribute("collapsed","false");
  78.     }
  79.  
  80. }
  81.  
  82. function updateBCMedialink() {
  83.     var enableItem=document.getElementById("cb-enable-medialink-method");
  84.     var bcItem=document.getElementById("bc-enable-medialink-method");
  85.     bcItem.setAttribute("collapsed",""+!enableItem.checked);
  86. }
  87.  
  88. function updateBCSmartName() {
  89.     var enableItem=document.getElementById("cb-enable-smartname");
  90.     var bcItem=document.getElementById("bc-enable-smartname");
  91.     bcItem.setAttribute("collapsed",""+!enableItem.checked);
  92. }
  93.  
  94. function updateBCHistory() {
  95.     var enableItem=document.getElementById("cb-history-enabled");
  96.     var bcItem=document.getElementById("bc-history-enabled");
  97.     bcItem.setAttribute("collapsed",""+!enableItem.checked);
  98. }
  99.  
  100. function updateBCMP3Tunes() {
  101.     var enableItem=document.getElementById("cb-mp3tunes-enabled");
  102.     var bcItem=document.getElementById("bc-mp3tunes-enabled");
  103.     bcItem.setAttribute("collapsed",""+!enableItem.checked);
  104. }
  105.  
  106. function updateBCYTInPage() {
  107.     var enableItem=document.getElementById("cb-ytinpage-enabled");
  108.     var bcItem=document.getElementById("bc-ytinpage-enabled");
  109.     bcItem.setAttribute("collapsed",""+!enableItem.checked);    
  110. }
  111.  
  112. function updateBCConversion() {
  113.     var enableItem=document.getElementById("cb-conversion-enabled");
  114.     var bcItem=document.getElementById("bc-conversion-enabled");
  115.     bcItem.setAttribute("collapsed",""+!enableItem.checked);
  116.     var cvMgr=Components.classes["@downloadhelper.net/convert-manager-component"]
  117.         .getService(Components.interfaces.dhIConvertMgr);
  118.     var props=cvMgr.getInfo();
  119.     if(props.has("license"))
  120.         document.getElementById("conv-license-license").value=props.get("license",Components.interfaces.nsISupportsString).data;
  121.     if(props.has("customername"))
  122.         document.getElementById("conv-license-name").value=props.get("customername",Components.interfaces.nsISupportsString).data;
  123.     if(props.has("customeremail"))
  124.         document.getElementById("conv-license-email").value=props.get("customeremail",Components.interfaces.nsISupportsString).data;
  125.     if(props.get("windows",Components.interfaces.nsISupportsPRBool).data) {
  126.         var bcConvRegistered=document.getElementById("bc-conv-registered");
  127.         var bcConvUnregistered=document.getElementById("bc-conv-unregistered");
  128.         if(props.get("unregistered",Components.interfaces.nsISupportsPRBool).data) {
  129.             bcConvRegistered.setAttribute("collapsed","true");
  130.             bcConvUnregistered.setAttribute("collapsed","false");
  131.         } else {
  132.             bcConvRegistered.setAttribute("collapsed","false");
  133.             bcConvUnregistered.setAttribute("collapsed","true");
  134.         }
  135.         var bcConvNotFound=document.getElementById("bc-conv-not-found");
  136.         bcConvNotFound.setAttribute("collapsed","true");
  137.         var bcConvBadVersion=document.getElementById("bc-conv-bad-version");
  138.         bcConvBadVersion.setAttribute("collapsed","true");
  139.         var exeOk=true;
  140.         if(!props.get("exefound",Components.interfaces.nsISupportsPRBool).data) {
  141.             exeOk=false;
  142.             bcConvNotFound.setAttribute("collapsed","false");
  143.         } else {
  144.             var version="1.0";
  145.             if(props.has("converterversion"))
  146.                 version=props.get("converterversion",Components.interfaces.nsISupportsString).data;
  147.             var minVersion="1.0";
  148.             if(props.has("converterminversion"))
  149.                 minVersion=props.get("converterminversion",Components.interfaces.nsISupportsString).data;
  150.             if(parseFloat(version)<parseFloat(minVersion)) {
  151.                 exeOk=false;
  152.                 bcConvBadVersion.setAttribute("collapsed","false");
  153.             }
  154.         }
  155.         var bcConvOk=document.getElementById("bc-conv-ok");
  156.         var bcConvKo=document.getElementById("bc-conv-ko");
  157.         if(exeOk) {
  158.             bcConvOk.setAttribute("collapsed","false");
  159.             bcConvKo.setAttribute("collapsed","true");
  160.         } else {
  161.             bcConvOk.setAttribute("collapsed","true");
  162.             bcConvKo.setAttribute("collapsed","false");
  163.         }
  164.     } else {
  165.         updateConvPath();
  166.     }
  167. }
  168.  
  169. function updateBCTwitter() {
  170.     var enableItem=document.getElementById("cb-twitter-enabled");
  171.     var bcItem=document.getElementById("bc-twitter-enabled");
  172.     bcItem.setAttribute("collapsed",""+!enableItem.checked);
  173. }
  174.  
  175. function updateBCMaxDownloads() {
  176.     var modeItem=document.getElementById("download-mode");
  177.     var bcItem=document.getElementById("bc-maxdownloads");
  178.     bcItem.setAttribute("collapsed",""+!(modeItem.value=="controlled"));
  179. }
  180.  
  181. function onHelp(event) {
  182.     var panelTopic=null;
  183.     var tabTopic=null;
  184.     var prefWindow=document.getElementById("dwhelper-preferences-new");
  185.     var prefPane=prefWindow.currentPane;
  186.     if(prefPane.hasAttribute("helpTopic"))
  187.         panelTopic=prefPane.getAttribute("helpTopic");
  188.     var node=prefPane.firstChild;
  189.     while(node) {
  190.         if(node.nodeName=="tabbox") {
  191.             var selTab=node.selectedTab;
  192.             if(selTab.hasAttribute("helpTopic"))
  193.                 tabTopic=selTab.getAttribute("helpTopic");
  194.         }
  195.         node=node.nextSibling;
  196.     }
  197.     var helpUrl="http://www.downloadhelper.net/pref-help-page.php";
  198.     if(panelTopic) {
  199.         helpUrl+="?topic="+panelTopic;
  200.         if(tabTopic)
  201.             helpUrl+=";"+tabTopic;
  202.     }
  203.     open(helpUrl);
  204. }
  205.  
  206. function configConvRules() {
  207.     var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  208.                                 .getService(Components.interfaces.nsIWindowMediator);
  209.     var w = wm.getMostRecentWindow("navigator:browser");
  210.     w.openDialog("chrome://dwhelper/content/conversion-rules.xul",
  211.         "dwhelper-conversion-rules",
  212.         "chrome,centerscreen,modal,resizable=yes");    
  213. }
  214.  
  215. function registerConverter() {
  216.     var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  217.                                 .getService(Components.interfaces.nsIWindowMediator);
  218.     var w = wm.getMostRecentWindow("navigator:browser");
  219.     /*
  220.     w.open("http://convert.downloadhelper.net/",
  221.         "dwhelper-convert-log","");
  222.     */    
  223.     w.open("chrome://dwhelper/content/convert-register.xul",
  224.         "dwhelper-convert-register",
  225.         "chrome,centerscreen,resizable=yes");    
  226. }
  227.  
  228. function showConversionLog() {
  229.     var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  230.                                 .getService(Components.interfaces.nsIWindowMediator);
  231.     var w = wm.getMostRecentWindow("navigator:browser");
  232.     w.open("chrome://dwhelper/content/convert-log.xul",
  233.         "dwhelper-convert-log",
  234.         "chrome,centerscreen,width=500,height=400,resizable=yes");    
  235. }
  236.  
  237. function updateConvPath() {
  238.     var prefConv=document.getElementById("converter").value;
  239.     if(document.getElementById("converter").value=="ffmpeg") {
  240.         document.getElementById("tb-converter-path-ffmpeg").setAttribute("collapsed","false");
  241.         document.getElementById("tb-converter-path-mencoder").setAttribute("collapsed","true");
  242.     } else {
  243.         document.getElementById("tb-converter-path-ffmpeg").setAttribute("collapsed","true");
  244.         document.getElementById("tb-converter-path-mencoder").setAttribute("collapsed","false");
  245.     }
  246.     updateConvFound(document.getElementById("tb-converter-path-"+prefConv));
  247. }
  248.  
  249. function updateConvFound(element) {
  250.     var path=element.value;
  251.     var file = Components.classes["@mozilla.org/file/local;1"]
  252.         .createInstance(Components.interfaces.nsILocalFile);
  253.     try {
  254.         file.initWithPath(path);
  255.         if(!file.exists()) {
  256.             element.style.color="Red";
  257.         } else {
  258.             element.style.color="Black";
  259.         }
  260.     } catch(e) {
  261.         element.style.color="Red";
  262.     }
  263. }
  264.  
  265. function installWinConverter() {
  266.     var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  267.                                 .getService(Components.interfaces.nsIWindowMediator);
  268.     var w = wm.getMostRecentWindow("navigator:browser");
  269.     w.open("http://www.downloadhelper.net/install-converter.php");
  270. }
  271.